const Mock = require('mockjs')

let list = []
const count = 3
const typeList = ['title', 'description', 'one_big_picture', 'list_of_clicks', 'list_of_products'];
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
const styleType = ['button', 'link', 'picture']
const modeType = ['wrap', 'unwrap']

for (let i = 0; i < count; i++) {
  list.push(random());
}

function random() {
  const items = []
  for (let i = 0; i < 3; i++) {
    items.push(Mock.mock({
      'data|1': [
        {
          type: 'title',
          text: '@title(5, 10)'
        },
        {
          type: 'description',
          text: '@paragraph(1)'
        },
        {
          type: 'one_big_picture',
          pict: image_uri,
          click: '@url',
        },
        {
          type: 'list_of_clicks',
          'style|1': styleType,
          'mode|1': modeType,
          'items|6': [
            {
              text: '@word(3, 5)',
              pict: image_uri,
              click: '@url',
            }
          ],
        },
        {
          type: 'list_of_products',
          'mode|1': modeType,
          'items|6': [
            {
              price: '$@integer(100, 999)',
              text: '@word(3, 5)',
              pict: image_uri,
              click: '@url',
            }
          ],
        }
      ]
    }).data)
  }
  return items;
}

module.exports = [
  /* section 获取 */
  {
    url: '/vue-element-admin/section/list',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: {
          list,
          typelist: typeList
        }
      }
    }
  },
  {
    url: '/vue-element-admin/section/update',
    type: 'post',
    response: config => {
      const { data } = config.body;
      list = JSON.parse(JSON.stringify(data));

      return {
        code: 20000,
        data: list
      }
    }
  },
]

